{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from sklearn.cluster import MiniBatchKMeans\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 载入数据\n",
    "data = np.genfromtxt(\"kmeans.txt\", delimiter=\" \")\n",
    "# 设置k值\n",
    "k = 4  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MiniBatchKMeans(batch_size=100, compute_labels=True, init='k-means++',\n",
       "        init_size=None, max_iter=100, max_no_improvement=10, n_clusters=4,\n",
       "        n_init=3, random_state=None, reassignment_ratio=0.01, tol=0.0,\n",
       "        verbose=0)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 训练模型\n",
    "model = MiniBatchKMeans(n_clusters=k)\n",
    "model.fit(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-2.48197142  2.76241754]\n",
      " [ 2.79592859 -2.75191228]\n",
      " [-3.44324364 -2.96140108]\n",
      " [ 2.56255895  3.16472295]]\n"
     ]
    }
   ],
   "source": [
    "# 分类中心点坐标\n",
    "centers = model.cluster_centers_\n",
    "print(centers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3\n",
      " 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0\n",
      " 1 2 3 0 1 2]\n"
     ]
    }
   ],
   "source": [
    "# 预测结果\n",
    "result = model.predict(data)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD8CAYAAABjAo9vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAG/xJREFUeJzt3X9sXNWVB/DvGcd2MglQkbhOBbGH\nbK1AlB9Q3KqISpsWsqKUghYqtnRAtKxqtWolEKnYEktbBTCKgtSyUisqawGhMlUTFizWyKsuDY12\npWW3DJTwIyEEpbb5UdKpq9AEJ07sOfvH88T2+M3Mm5n7ft33/UjR4OfnmTsz7Zk75517rqgqiIjI\nHqmwB0BERGYxsBMRWYaBnYjIMgzsRESWYWAnIrIMAzsRkWUY2ImILMPATkRkGQZ2IiLLLAnjQVet\nWqWZTCaMhyYiiq2XX375z6raUeu8UAJ7JpNBPp8P46GJiGJLRMa8nMdUDBGRZRjYiYgsw8BORGQZ\nBnYiIsswsBMRWYaBnYgAAEeP5vDiixns25fCiy9mcPRoLuwhUYMY2IkIR4/mcOhQH6amxgAopqbG\ncOhQn1XBPUkfXAzsRIQjR/pRLE4uOFYsTuLIkf6QRmRWEj645mNgJyJMTY3XdTxubP/gKsfATkRo\nb++q63jc2P7BVY6BnYiwdu0AUqn0gmOpVBpr1w6ENCKzbP/gKsfATkTo7Mxi3bpBtLd3AxC0t3dj\n3bpBdHZmwx6aEbZ/cJULpQkYEUVPZ2fWmkBervS8jhzpx9TUONrbu7B27YC1z5eBnYgSweYPrnJM\nxRARWYaBnYjIMgzsRESWYWAnIrIMAzsRkW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gGwGUA/i/c\nkfjqYTiTsGLYAzGBm1k3QUR+A2C1y6/6AWwH8HfBjshf1Z6vqj47e04/nK/xuSDHFgBxOWb9NzER\nWQHgaQB3qepfwx6PH0TkOgB/UtWXRWRL2OMxgYG9Cap6tdtxEdkI4CIA+0UEcNISr4jI51T1wwCH\naFSl51siIrcDuA7AVWpfHe17ANbM+/lCAB+ENJZAiEgrnKCeU9Vnwh6Pj64EcL2IXAtgKYBzReRJ\nVb015HE1jHXsARCRUQC9qhrl5kJNEZFrAPwYwN+qaiHs8ZgmIkvgXBS+CsD7AF4C8A1VfTPUgflE\nnBnJEwD+oqp3hT2eoMzO2H+gqteFPZZmMMdOpvwUwDkAnheRV0Xk52EPyKTZC8PfB/BrOBcS99ga\n1GddCeA2AF+afT9fnZ3RUgxwxk5EZBnO2ImILMPATkRkGQZ2IiLLMLATEVmGgZ2IyDIM7ERElmFg\nJyKyDAM7EZFl/h/2Sox1kbsFDwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1eff0473b70>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画出各个数据点，用不同颜色表示分类\n",
    "mark = ['or', 'ob', 'og', 'oy']\n",
    "for i,d in enumerate(data):\n",
    "    plt.plot(d[0], d[1], mark[result[i]])\n",
    "\n",
    "# 画出各个分类的中心点\n",
    "mark = ['*r', '*b', '*g', '*y']\n",
    "for i,center in enumerate(centers):\n",
    "    plt.plot(center[0],center[1], mark[i], markersize=20)\n",
    "    \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD8CAYAAABjAo9vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCB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TRK5V1ZMxDrFutX5uACAiXwZwJ4Cb03IiruEYgLVzPl4D\n4HhCYwmViDSgHOq7VfXppMcTohsA3CUinwfQBKBNRP5aVe9NeFyRM76PXUS+CmC1qv6BiFwG4J8B\nrLMgKOYRkcMAtqiqDRsVQURuB/DHAD6tqqk4CdciIgWUF4FvBvAhgNcBfFFV9yc6sICkPKv4nwA+\nUtVvJD2eqFRm7A+q6p1JjyUOaaix/xWAS0XkZygvWH3ZtlC31J8AKAJ4QUTeFpE/T3pAQVQWgn8P\nwHMoLzD+IO2hXnEDgC8BuKnyc3q7MsOlFDN+xk5ERP6kYcZOREQ+MNiJiCzDYCcisgyDnYjIMgx2\nIiLLMNiJiCzDYCcisgyDnYjIMv8fBm52jUREp+EAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1efe6657f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 获取数据值所在的范围\n",
    "x_min, x_max = data[:, 0].min() - 1, data[:, 0].max() + 1\n",
    "y_min, y_max = data[:, 1].min() - 1, data[:, 1].max() + 1\n",
    "\n",
    "# 生成网格矩阵\n",
    "xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02),\n",
    "                     np.arange(y_min, y_max, 0.02))\n",
    "\n",
    "z = model.predict(np.c_[xx.ravel(), yy.ravel()])# ravel与flatten类似，多维数据转一维。flatten不会改变原始数据，ravel会改变原始数据\n",
    "z = z.reshape(xx.shape)\n",
    "# 等高线图\n",
    "cs = plt.contourf(xx, yy, z)\n",
    "# 显示结果\n",
    "# 画出各个数据点，用不同颜色表示分类\n",
    "mark = ['or', 'ob', 'og', 'oy']\n",
    "for i,d in enumerate(data):\n",
    "    plt.plot(d[0], d[1], mark[result[i]])\n",
    "\n",
    "# 画出各个分类的中心点\n",
    "mark = ['*r', '*b', '*g', '*y']\n",
    "for i,center in enumerate(centers):\n",
    "    plt.plot(center[0],center[1], mark[i], markersize=20)\n",
    "    \n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
